<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">
Ext.namespace('catalog.catalog.teacherCatalog');

catalog.catalog.teacherCatalog.SearchPanel = Ext.extend(catalog.ComplexEditorGrid, {
lastName:'Nume',
userName:'Nume utilizator',
firstName:'Prenume',
grade:'Note',
absence:'Absente',
firstSem:'Medie sem I',
secondSem:'Medie sem II',
finalAvg:'Medie finala' ,


initComponent:function() {
 searchURL = 'displayStudentsByClass.action?classId=' +<%=request.getParameter("classId")%>;

var config = {
compSet:[{url:0,reader:0,columns:0,bbarAction:0}],
searchFields :[[
                this.lastName, {xtype:'textfield', name:'teacherDisciplineStudentsDTO.lastName', width:120}
                ]],
                urls: [searchURL],
                readers : [[
                {name: 'id'},
                {name: 'lastName'},
                {name: 'firstName'},
                {name: 'gradeNo'},
                {name:'absenceNo'},
                {name: 'firstSemAvg'},
                {name: 'secondSemAvg'},
                {name: 'finalAvg'}
                ]],
columnsArray: [[
                {header: this.lastName, width: 100, sortable: true, dataIndex: 'lastName'},
                {header: this.firstName, width: 180, sortable: true, dataIndex: 'firstName'},
                {header: this.grade, width: 90, sortable: true, dataIndex: 'gradeNo'},
                {header: this.absence, width: 70, sortable: true, dataIndex: 'absenceNo'},
                {header: this.firstSem, width: 70, sortable: true, dataIndex: 'firstSemAvg'},
                {header: this.secondSem, width: 70, sortable: true, dataIndex: 'secondSemAvg'},
                {header: this.finalAvg, width: 70, sortable: true, dataIndex: 'finalAvg'}

               // sm
                ]],

bbarActions:[[{
            text:'Absente',
            iconCls :'info-icon',
            scope:this,
            handler:this.addAbsenceFun
            },{
            text:'Note',
            iconCls :'info-icon',
            scope:this,
            handler:this.addGradeFun
            },{
            text:'Elevi promovati',
            iconCls :'info-icon',
            scope:this,
            handler:this.addPromotedFun
             },{
            text:'Elevi nepromovati',
            iconCls :'info-icon',
            scope:this,
            handler:this.addUnPromotedFun
              }]],
  autoScroll:true
}; // eo config object

Ext.apply(this, Ext.apply(this.initialConfig, config));
    catalog.catalog.teacherCatalog.SearchPanel.superclass.initComponent.apply(this, arguments);
    },

addAbsenceFun :function() {
                var studentId = this.selModel.selections.keys;
                if (studentId.length <= 0) {
                Ext.MessageBox.alert(mbLocale.infoMsg,'Va rugam selectati un elev');
                return;
                }
                   var student= this.selModel.getSelections();
                   var win = catalog.util.genWindow({
                       id: 'absenceSelectWindow',
                       title    :  student[0].get('lastName')+' '+student[0].get('firstName'),
                       autoLoad : {url: 'catalog/absenceSelect.jsp?studentId='+student[0].get('id'),scripts:true},
                       width    : 600,
                       height   : 400,
                       border   : true
                   });
                },
addGradeFun :function() {
               var studentId = this.selModel.selections.keys;
                            if (studentId.length <= 0) {
                            Ext.MessageBox.alert(mbLocale.infoMsg,'Va rugam selectati un elev');
                            return;
                            }
                               var student= this.selModel.getSelections();
                               var win = catalog.util.genWindow({
                                   id: 'gradeSelectWindow',
                                   title    :  student[0].get('lastName')+' '+student[0].get('firstName'),
                                   autoLoad : {url: 'catalog/gradeSelect.jsp?studentId='+student[0].get('id'),scripts:true},
                                   width    : 600,
                                   height   : 400,
                                   border   : true
                               });
            },
addPromotedFun :function() {

                               var classId= <%=request.getParameter("classId")%>;
                               var win = catalog.util.genWindow({
                                   id: 'gradePromotedWindow',
                                   title    :  'Lista elevi promovati',
                                   autoLoad : {url: 'catalog/raportPromovat.jsp?classId='+classId,scripts:true},
                                   width    : 600,
                                   height   : 400,
                                   border   : true
                               });
            },
addUnPromotedFun :function() {
               var classId= <%=request.getParameter("classId")%>;
                                             var win = catalog.util.genWindow({
                                                 id: 'gradeUnPromotedWindow',
                                                 title    :  'Lista elevi nepromovati',
                                                 autoLoad : {url: 'catalog/raportNepromovat.jsp?classId='+classId,scripts:true},
                                                 width    : 600,
                                                 height   : 400,
                                                 border   : true
                                               });
                }
});
try {teacherCatalogLocale();} catch (e) {}

Ext.onReady(function() {
            Ext.QuickTips.init();
            var formPanel = new catalog.catalog.teacherCatalog.SearchPanel();
                formPanel.store.reload();
            if (mainPanel) {
            mainPanel.getActiveTab().add(formPanel);
            mainPanel.getActiveTab().doLayout();
            } else {
            var vp = new Ext.Viewport({
            layout:'fit',
            items:[formPanel]
            });
            }
            });
</script>